package com.alan.springBoot.config;

import com.alibaba.fastjson.serializer.SerializerFeature;
import com.alibaba.fastjson.support.config.FastJsonConfig;
import com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

import com.alan.springBoot.interceptor.MyInterceptor;
import com.alan.springBoot.interceptor.MyInterceptor2;

import java.util.List;

@Configuration
public class WebMvcConfig extends WebMvcConfigurerAdapter {

	@Override
	public void addInterceptors(InterceptorRegistry registry) {
		registry.addInterceptor(new MyInterceptor()).addPathPatterns("/test/**");
		/*registry.addInterceptor(new MyInterceptor2()).addPathPatterns( "/test2/**" )
			.excludePathPatterns( "/test/hello1" );*/
		super.addInterceptors( registry );
	}

	/**
	 * FastJson
	 * @Author Alan liu
	 * @Date 11:18 2019/8/9
	 * @param converters
	 * @return void
	 **/
//	@Override
//	public void configureMessageConverters(
//			List<HttpMessageConverter<?>> converters) {
//		//定义一个converter转换消息的对象
//		FastJsonHttpMessageConverter fastconverter = new FastJsonHttpMessageConverter();
//		//添加fastjson的配置信息，比如：是否需要格式化返回的json数据
//		FastJsonConfig fastJsonConfig = new FastJsonConfig();
//		fastJsonConfig.setSerializerFeatures(SerializerFeature.PrettyFormat);
//		//在converter中添加配置信息
//		fastconverter.setFastJsonConfig(fastJsonConfig);
//		//将converter添加到converters中
//		converters.add(fastconverter);
//	}
	
}
